var noteTypeList=new Array();
var cookies={};

function initCookies()
{
	var ids=Cookie.get("_noteTypes");

	if(ids!=null && ids!=false)
	{
		var idList=(ids+"").split('_');
		if(idList!=null && idList.length>0)
		{
			for(var i=0;i<idList.length;i++)
			{
				cookies[idList[i]]=true;
			}
		}
	}
}

function saveCookies()
{
	var value=null;
	if(cookies!=null)
	{		
		for(var k in cookies)
		{
			if(cookies[k]==true)
			{
				if(value==null)
					value=k;
				else
					value+="_"+k;
			}
		}
	}

	Cookie.set('_noteTypes',value,{duration:100});

	top.topFrame.changeConfig=true;	
}

function NoteType()
{
	this.id;
	this.name;
	this.ico;
	this.remark;
	this.selected;

	this.index;
	this.div;
}

NoteType.prototype.init=function()
{
	this.div=document.createElement("DIV");
	$("noteTypesArea").appendChild(this.div);

	this.refresh();
}

NoteType.prototype.select=function()
{
	cookies[this.id]=true;
	this.selected=true;

	this.refresh();
	top.topFrame.changeConfig=true;
}

NoteType.prototype.cancel=function()
{
	cookies[this.id]=null;
	this.selected=false;

	this.refresh();
	top.topFrame.changeConfig=true;
}

NoteType.prototype.refresh=function()
{
	if(this.div!=null)
	{
		var html=this.name;
		if(this.selected)
		{
			this.div.className="selected";
			html+="[<a href='javascript:noteTypeList["+this.index+"].cancel()'>Remove</a>]";
		}
		else
		{
			this.div.className="unselected";
			html+="[<a href='javascript:noteTypeList["+this.index+"].select()'>Add</a>]";
		}
		html+="<br>&nbsp;&nbsp;"+this.remark;
		this.div.innerHTML=html;
	}
}

function _initNoteTypes(noteTypes)
{
	noteTypeList=new Array();

	if(noteTypes!=null && noteTypes.length>0)
	{
		for(var i=0;i<noteTypes.length;i++)
		{
			var data=noteTypes[i];
			var nt=new NoteType();
			nt.id=data[0];
			nt.name=data[1];
			nt.ico=data[2];
			nt.remark=data[3];

			if(cookies[nt.id]!=null)
				nt.selected=true;
			else
				nt.selected=false;

			nt.index=i;
			noteTypeList[i]=nt;

			nt.init();
		}
	}
}

initEvents.push(initCookies);
initEvents.push("CalendarAction.noteTypes(_initNoteTypes)");


